<html><head>
<meta http-equiv=Content-Type Content="text-html; charset=utf-8">
<meta http-equiv=MSThemeCompatible Content=Yes>
<hta:application
id=SWI
applicationName=SciTE_Windows_Integrator
icon=wuauclt.exe
maximizeButton=no
innerBorder=no
border=thin
scroll=no
selection=no
contextMenu=no
singleinstance=yes
version=4.1.1
>
<style type="text/css">
	body {margin:4px;}

	td, input {
		font:normal normal 10px MS Shell Dlg;
		white-space:nowrap;
		margin:0;
	}

	body, table {
		background-color:threedface;
	}

	input.btn {width:95px;}

	legend {
		font-size:10px;
		color:highlight;
		font-weight:bold;
	}

	label {
		cursor:hand;
		white-space:nowrap;
	}

	a.help {
		font:normal normal 8pt arial,sans-serif;
		text-decoration:none
	}

	a.help:hover {
		position:relative;
		cursor:help;
	}

	a.help span.help {
		display:none;
	}

	a.help:hover span.help {
		margin:2;
		color:black;
		display:block;
		position:absolute;
		top:20px;
		left:20px;
		background-color:white;
		border:1px solid #999999;
		padding:5px;
		cursor:help;
	}

	cite {
		color:#0033CC;
		font-style:normal;
	}
</style>
<script language="JavaScript">
var dialogWidth = 450;
window.resizeTo(dialogWidth, 0);
document.title = SWI.applicationName.replace(/_/g,' ') + ' ' + SWI.version;

var WshShell = new ActiveXObject("WScript.Shell");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var script_path = unescape(self.location.href).replace(/file:\/\/\/([a-z]:.*)\/.*?$/i,'$1').replace(/\//g,'\\');
var reg_backup = 'HKLM\\SOFTWARE\\SciTE\\Script\\WinIntegrator\\';
var scite_path = '';

// Language =============================================
function Locale(lng){
	var filename = scite_path + "\\SciTEGlobal.properties";
	if (fso.FileExists(filename)){
		if (fso.GetFile(filename).Size > 0) {
			var file = fso.OpenTextFile(filename);
			var text = file.ReadAll();
			file.Close();
			var re = new RegExp("([^\r\n]*)(locale.properties=locale-ru.properties)","ig");
			var arr_match = re.exec(text);
			if ((arr_match)&&(arr_match[1]=='')) {
				if (lng!='eng') return 'rus';
				// Set English
				text = text.replace(re, '$1#~ $2');
			}else{
				if (lng!='rus') return 'eng';
				if ((fso.FileExists(scite_path + "\\locale-ru.properties"))) {
					// Set Russian
					text = text.replace(re, '$2');
				} else {
					alert("Русификация интерфейса SciTE невозможна ввиду отсутствия файла\n" + scite_path + "\\locale-ru.properties");
					return false;
				}
			};
			file = fso.OpenTextFile(filename, 2);
			file.Write(text);
			file.Close();
			return true;
		}
	}
}

function SetInterfaceLng(lng){
	if (lng == 'eng'){
		lng_legend.innerHTML = "&nbsp;Interface Language:&nbsp;";
		lng_help[0].innerHTML = "Change interface this application<br>SciTE Interface will change after restart";
		lng_help[1].innerHTML = lng_help[0].innerHTML;
		lng_label[0].innerHTML = "English";
		lng_label[1].innerHTML = "Russian";

		explorer_legend.innerHTML = "&nbsp;Integration with Explorer:&nbsp;";
		explorer_text.innerHTML = "&nbsp;Associate SciTE with extensions:";
		explorer_help[0].innerHTML = "You\'ll able to open in SciTE files with this extensions by double click.";
		explorer_help[1].innerHTML = "You\'ll able to open any selected files with SciTE";
		explorer_label[0].innerHTML = 'Add SciTE to "SendTo" context menu';
		explorer_help[2].innerHTML = "You\'ll able to open SciTE session files by double click";
		explorer_label[1].innerHTML = 'Associate files *.session as SciTE session files';

		ie_legend.innerHTML = "&nbsp;Integration with Internet Explorer:&nbsp;";
		ie_help[0].innerHTML = "Command \'<cite>View source</cite>\' will open source file in SciTE";
		ie_label[0].innerHTML = "Set SciTE as default HTML editor";
		ie_help[1].innerHTML = "On Internet Explorer toolbar can be placed button '<cite>Edit</cite>'.<br>This option add the command '<cite>Edit with SciTE</cite>'";
		ie_label[1].innerHTML = 'SciTE as one editor from button menu "Edit"';

		win_legend.innerHTML = "&nbsp;Integration with Windows:&nbsp;";
		win_help.innerHTML = "<cite>SciTE.Helper</cite> is needed for external scripts for communicate with SciTE.";
		win_label.innerHTML = "Install SciTE.Helper (COM-server for communication with SciTE)";

		form.btn_cancel.value = "Cancel";
		form.btn_about.value = "About";

		alert_msvbvm50_locale = '<font color=red>Can\'t register <b>SciTE.Helper</b></font> in your sistem,<br> because required library <a href="http://www.google.com/search?q=MSVBVM50.DLL" target="_blank"><b>MSVBVM50.DLL</b></a> is absent.<br><br>For more information <a href="http://code.google.com/p/scite-ru/issues/detail?id=62" target="_blank"><b>Issue 62</b></a>';
		open_with_scite_locale = "Open with &SciTE";

	}else{
		lng_legend.innerHTML = "&nbsp;Язык интерфейса:&nbsp;";
		lng_help[0].innerHTML = "Сменить интерфейс этого приложения<br>Интерфейс SciTE изменится после перезапуска";
		lng_help[1].innerHTML = lng_help[0].innerHTML;
		lng_label[0].innerHTML = "Английский";
		lng_label[1].innerHTML = "Русский";

		explorer_legend.innerHTML = "&nbsp;Интеграция в Проводник:&nbsp;";
		explorer_text.innerHTML = "&nbsp;Связать файлы заданных расширений с SciTE:";
		explorer_help[0].innerHTML = "Позволяет открывать в SciTE файлы ассоциированных типов<br>с помощью двойного клика мыши";
		explorer_help[1].innerHTML = "Позволяет открывать в SciTE любые выбранные файлы";
		explorer_label[0].innerHTML = 'Добавить SciTE в контекстное меню "Отправить"';
		explorer_help[2].innerHTML = "Позволяет открывать сохраненные ранее сессиии SciTE";
		explorer_label[1].innerHTML = 'Открывать файлы *.session как файлы сессий SciTE';

		ie_legend.innerHTML = "&nbsp;Интеграция в Internet Explorer:&nbsp;";
		ie_help[0].innerHTML = "Выбор пункта меню Internet Explorer \'<cite>Просмотр HTML кода</cite>\'<br>откроет текущую страницу в SciTE";
		ie_label[0].innerHTML = "Установить SciTE в качестве дефолтового HTML редактора";
		ie_help[1].innerHTML = "На панели инструментов Internet Explorer можно установить кнопку \'<cite>Правка</cite>\'.<br>Данная опция добавит в меню этой кнопки пункт \'<cite>Править в SciTE</cite>\'";
		ie_label[1].innerHTML = 'SciTE в качестве одного из редакторов в меню кнопки "Правка"';

		win_legend.innerHTML = "&nbsp;Интеграция в Windows:&nbsp;";
		win_help.innerHTML = "C помощью <cite>SciTE.Helper</cite> внешние скрипты и программы<br>смогут управлять SciTE и получать из него данные";
		win_label.innerHTML = "Установить SciTE.Helper (COM-сервер для управления SciTE)";

		form.btn_cancel.value = "Отмена";
		form.btn_about.value = "О программе";

		alert_msvbvm50_locale = '<b>SciTE.Helper</b> <font color=red>не был зарегистрирован</font> в Вашей системе,<br>поскольку для его работы необходим <a href="http://www.google.com/search?q=MSVBVM50.DLL" target="_blank"><b>MSVBVM50.DLL</b></a>.<br><br>Подробности изложены в <a href="http://code.google.com/p/scite-ru/issues/detail?id=62" target="_blank"><b>Issue 62</b></a>';
		open_with_scite_locale = "Открыть в &SciTE";
	}
	window.resizeTo(dialogWidth, form.offsetHeight+35);
}

function CheckLanguage(){
	if (Locale()=='rus'){
		form.chk_lng[1].checked = true;
		SetInterfaceLng('rus');
	}else{
		form.chk_lng[0].checked = true;
		SetInterfaceLng('eng');
	}
}

// associations ============================================
function CheckAssociations(){
	form.chk_associations.checked = false;
	form.chk_associations.value = false;
	form.associations.value = "txt;php;h;cxx";
	form.associations.disabled = true;
	try {
		var _associations = WshShell.RegRead(reg_backup+'associations');
		form.chk_associations.checked = true;
		form.chk_associations.value = true;
		form.associations.value = _associations;
		form.associations.disabled = false;
	} catch(e) {}
}

function SetAssociations(){
	var Arr_associations = form.associations.value.split(';');
	for (var i=0;i<Arr_associations.length;i++){
		var ext = Arr_associations[i];
		if (ext !== ''){
			var current_association = "";
			try {current_association = WshShell.RegRead('HKCR\\.'+ext+'\\');} catch(e) {}
			WshShell.RegWrite(reg_backup+ext, current_association);
			WshShell.RegWrite('HKCR\\.'+ext+'\\', 'SciTE.File');
		}
	}
	WshShell.RegWrite(reg_backup+'associations', form.associations.value);
	WshShell.RegWrite('HKCR\\SciTE.File\\', 'SciTE file');
	WshShell.RegWrite('HKCR\\SciTE.File\\DefaultIcon\\', scite_path + '\\SciTE.exe,1');
	WshShell.RegWrite('HKCR\\SciTE.File\\shell\\open\\command\\', '"' + scite_path + '\\SciTE.exe" "%1"');
	return true;
}

function UnSetAssociations(){
	var Arr_associations = WshShell.RegRead(reg_backup+'associations').split(';');
	for (var i=0;i<Arr_associations.length;i++){
		var ext = Arr_associations[i];
		if (ext !== ''){
			var old_association = "";
			try {
				old_association = WshShell.RegRead(reg_backup+ext);
				WshShell.RegDelete(reg_backup+ext);
			} catch(e) {}
			WshShell.RegWrite('HKCR\\.'+ext+'\\', old_association);
		}
	}
	WshShell.RegDelete(reg_backup+'associations');
	return true;
}

// openfor =================================================
function CheckOpenfor(){
	if (fso.FileExists(WshShell.SpecialFolders("SendTo") + "\\SciTE.lnk")) {
		form.chk_openfor.checked = true;
		form.chk_openfor.value = true;
	} else {
		form.chk_openfor.checked = false;
		form.chk_openfor.value = false;
	}
}

function SetOpenfor(){
	with (WshShell.CreateShortcut(WshShell.SpecialFolders("SendTo") + "\\SciTE.lnk")){
		TargetPath = scite_path + '\\SciTE.exe';
		Save();
	}
	return true;
}

function UnSetOpenfor(){
	try {
		fso.DeleteFile(WshShell.SpecialFolders("SendTo") + "\\SciTE.lnk", true);
		return true;
	}catch(e){return false;}
}

// session =================================================
var open_ses_file = 'open_session.js';

function CheckSession(){
	form.chk_ses.checked = false;
	form.chk_ses.value = false;
	try {
		var _ses = WshShell.RegRead('HKCR\\.session\\');
		if (fso.FileExists(script_path + '\\' + open_ses_file)){
			form.chk_ses.checked = true;
			form.chk_ses.value = true;
		}
	} catch(e) {}
}

function SetSessions(){
	WshShell.RegWrite('HKCR\\.session\\', 'SciTE.Session');
	WshShell.RegWrite('HKCR\\SciTE.Session\\', 'SciTE session file');
	WshShell.RegWrite('HKCR\\SciTE.Session\\DefaultIcon\\', scite_path + '\\SciTE.exe,2');
	WshShell.RegWrite('HKCR\\SciTE.Session\\shell\\open\\command\\', 'cmd /v:on /c "set "file=%1" && start "" "' + scite_path.replace(/\\/g,'\\\\') + '\\\\SciTE.exe" -check.if.already.open=0 "-loadsession:!file:\\=\\\\!"');
	return true;
}

function UnSetSessions(){
	try{WshShell.RegDelete('HKCR\\.session\\');}catch(e){return false;}
	return true;
}

// html_def ================================================
function CheckHTML_def(){
	form.chk_html_def.checked = false;
	form.chk_html_def.value = false;
	try {
		var _html_def = WshShell.RegRead('HKLM\\SOFTWARE\\Microsoft\\Internet Explorer\\View Source Editor\\Editor Name\\');
		if (/scite/i.test(_html_def)){
			form.chk_html_def.checked = true;
			form.chk_html_def.value = true;
		}
	} catch(e) {}
}

function SetHTML_def(){
	var current_htmldef = "";
	try {current_htmldef = WshShell.RegRead('HKLM\\SOFTWARE\\Microsoft\\Internet Explorer\\View Source Editor\\Editor Name\\');} catch(e) {}
	WshShell.RegWrite(reg_backup+'Source Editor', current_htmldef);
	WshShell.RegWrite('HKLM\\SOFTWARE\\Microsoft\\Internet Explorer\\View Source Editor\\Editor Name\\', '"' + scite_path + '\\SciTE.exe"');
	return true;
}

function UnSetHTML_def(){
	var old_htmldef = "";
	try {
		old_htmldef = WshShell.RegRead(reg_backup+'Source Editor');
		WshShell.RegDelete(reg_backup+'Source Editor');
	} catch(e) {}
	WshShell.RegWrite('HKLM\\SOFTWARE\\Microsoft\\Internet Explorer\\View Source Editor\\Editor Name\\', old_htmldef);
	return true;
}

// html ====================================================
function CheckHTML(){
	form.chk_html.checked = false;
	form.chk_html.value = false;
	try {
		var _html = WshShell.RegRead('HKCR\\.htm\\OpenWithList\\SCITE.EXE\\');
		form.chk_html.checked = true;
		form.chk_html.value = true;
	} catch(e) {}
}

function SetHTML(){
	WshShell.RegWrite('HKCR\\.htm\\OpenWithList\\SCITE.EXE\\', '');
	WshShell.RegWrite('HKCR\\Applications\\SCITE.EXE\\shell\\edit\\command\\', scite_path + '\\SciTE.exe "%1"');
	try {WshShell.RegDelete('HKCU\\Software\\Microsoft\\Internet Explorer\\Default HTML Editor\\shell\\edit\\ddeexec\\');} catch(e) {}
	WshShell.RegWrite('HKCU\\Software\\Microsoft\\Internet Explorer\\Default HTML Editor\\shell\\edit\\command\\', scite_path + '\\SciTE.exe "%1"');
	WshShell.RegWrite('HKCU\\Software\\Microsoft\\Internet Explorer\\Default HTML Editor\\Description', 'SciTE - a Scintilla based Text Editor');
	WshShell.RegWrite('HKCU\\Software\\Microsoft\\Shared\\HTML\\Default Editor\\shell\\edit\\command\\', scite_path + '\\SciTE.exe "%1"');
	return true;
}

function UnSetHTML(){
	try{WshShell.RegDelete('HKCR\\.htm\\OpenWithList\\SCITE.EXE\\');} catch(e) {return false;}
	return true;
}

// =============================================================
// Окно "msvbvm50.dll"
function AlertMSVBVM50() {
	var html = '<html><head>';
	html += '<title>SciTE.Helper Install Error<\/title>';
	html += '<meta http-equiv="content-type" content="text\/html; charset=windows-1251">';
	html += '<\/head><style>body{text-align:center; background-color:infobackground; font-family:verdana; font-size:10pt; a{color:#000080; text-decoration:none;} a:hover{color:red;}<\/style><body>';
	html += alert_msvbvm50_locale;
	html += '<\/body><\/html>';
	var WinAlert = window.open("about:blank", "", "height=80,width=450,status=no,toolbar=no,menubar=no,location=no");
	WinAlert.document.write(html);
}

// helper ==================================================
function CheckHelper(){
	form.chk_helper.checked = false;
	form.chk_helper.value = false;
	try {
		var _helper = new ActiveXObject("SciTE.Helper");
		form.chk_helper.checked = true;
		form.chk_helper.value = true;
	} catch(e) {}
}

function SetHelper(){
	var file_dll = scite_path + '\\tools\\Helper\\SciTE.dll';
	if (fso.FileExists(file_dll)){
	var ret = WshShell.Run('cmd /c for /f %i in ("msvbvm50.dll") do if "%~$PATH:i"=="" exit /b 1', 0, true);
		if (ret !== 0) {
			AlertMSVBVM50();
			return false;
		} else {
			WshShell.Run('Regsvr32 "' + file_dll + '"', 1, false);
		}
	}
	return true;
}

function UnSetHelper(){
	var file_dll = scite_path + '\\tools\\Helper\\SciTE.dll';
	if (fso.FileExists(file_dll)){
		WshShell.Run('Regsvr32 /u "' + file_dll + '"', 1, false);
	}
	return true;
}

// =============================================================
// Установка регистрации
function SetValue(id){
	switch(id){
	case "chk_associations":
		return SetAssociations();
	case "chk_openfor":
		return SetOpenfor();
	case "chk_ses":
		return SetSessions();
	case "chk_html_def":
		return SetHTML_def();
	case "chk_html":
		return SetHTML();
	case "chk_helper":
		return SetHelper();
	}
}

// Снятие регистрации
function UnSetValue(id){
	switch(id){
	case "chk_associations":
		return UnSetAssociations();
	case "chk_openfor":
		return UnSetOpenfor();
	case "chk_ses":
		return UnSetSessions();
	case "chk_html_def":
		return UnSetHTML_def();
	case "chk_html":
		return UnSetHTML();
	case "chk_helper":
		return UnSetHelper();
	}
}

// После нажатия на "ОК" проверяем, изменил ли пользователь установки
// и выполняем только те позиции, в которых состояние чекбоксов изменилось
function Set(){
	// --------------------------------
	if (form.chk_lng[0].checked){
		if (!Locale('eng')){return false;}
	}else{
		if (!Locale('rus')){return false;}
	}
	for (i=0;i<form.chk.length;i++){
		if (form.chk[i].checked.toString() != form.chk[i].value.toString()){
			if (form.chk[i].checked){
				if (!SetValue(form.chk[i].id)) {return false;}
			}else{
				if (!UnSetValue(form.chk[i].id)) {return false;}
			}
		}
	}
	// --------------------------------
	self.close();
}

// =============================================================
// Окно "О программе"
function About() {
	var ver = SWI.version;
	var text = '<html><head>';
	text += '<title>'+form.btn_about.value+'</title>';
	text += '<meta http-equiv="content-type" content="text\/html; charset=windows-1251"><style>body {font-family:arial, verdana; font-size:x-small; background-color:black; color:white; text-align:center; overflow:hidden;} h1,h2{width:100%;} h1{font:bold normal 40px impact; color:#0eda05; filter:shadow(color=#6699cc,direction=135);} h2{margin-top:-30px; margin-bottom:8px; font:bold italic 20px arial;color:#e5e1b1; filter:shadow(color=#84602c, direction=135);} a{color:white; text-decoration:none;} a:hover{color:#99ffff;} hr{width:90%;} p{margin-top:-8px;}<\/style><\/head>';
	text += '<body><h1>SciTE<\/h1><h2>Windows Integrator<\/h2>';
	text += 'Version <b>'+ver+'<\/b>';
	text += '<hr size=1px><p>';
	text += '<b><a href="mailto:mozers@mail.ru?subject=SciTE_Windows_Integrator_'+ver+'">mozers&trade;<\/a><\/b> and <b><a href="mailto:vladvro@gmail.com?subject=SciTE_Windows_Integrator_'+ver+'">VladVRO<\/a><\/b>';
	text += '<\/body><\/html>';
	var WinAbout = showModelessDialog('about:blank', '', 'status:no; help:no; dialogWidth:250px; dialogHeight:140px;');
	WinAbout.document.write(text);
}

// =============================================================
// Инициализация формы
function CheckSciTE(scite_path){
	if (fso.FileExists(scite_path + "\\SciTE.exe")){
		return true;
	}else{
		return false;
	}
}

function FindSciTE(){
	var scite_path = script_path;
	if (CheckSciTE(scite_path)){
		return scite_path;
	}else{
		scite_path = scite_path.replace(/\\[^\\]+$/,'');
		if (CheckSciTE(scite_path)){
			return scite_path;
		}else{
			return "";
		}
	}
}

function LoadForm(){
	scite_path = FindSciTE();
	if (scite_path === ""){
		alert("Can't find SciTE!\nPlease run this script from folder with SciTE");
		self.close();
	}

	CheckLanguage();
	CheckAssociations();
	CheckOpenfor();
	CheckSession();
	CheckHTML_def();
	CheckHTML();
	CheckHelper();
}

</script>
</head>
<body onLoad="LoadForm()">
<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>
<form id="form">

<fieldset><legend id="lng_legend"></legend><table width=100%>
	<tr>
		<td width="35%">
			<a class="help" href="#" hidefocus>
			<input type="radio" name=chk_lng hidefocus onClick="SetInterfaceLng('eng');">
			<span class="help" id="lng_help"></span></a>
			<label id="lng_label" onClick="form.chk_lng[0].checked = true; SetInterfaceLng('eng');"></label>
		</td>
		<td width="65%">
			<a class="help" href="#" hidefocus>
			<input type="radio" name=chk_lng hidefocus onClick="SetInterfaceLng('rus');">
			<span class="help" id="lng_help"></span></a>
			<label id="lng_label" onClick="form.chk_lng[1].checked = true; SetInterfaceLng('rus');"></label>
		</td>
	</tr>
</table></fieldset>

<fieldset style="margin-top:4pt"><legend id="explorer_legend"></legend>
<table width=100%>
	<tr>
		<td colspan="2" id="explorer_text"></td>
	</tr>
	<tr>
		<td>
			<a class="help" href="#" hidefocus>
			<input name="chk" type="checkbox" id=chk_associations hidefocus onClick="associations.disabled=!chk_associations.checked">&nbsp;
			<span class="help" id="explorer_help"></span></a>
		</td>
		<td style="width:100%">
			<input TYPE=text id="associations" style="width:100%; font:normal normal 10pt Courier New;">
		</td>
	</tr>
</table>
<table width=100%>
	<tr>
		<td>
			<a class="help" href="#" hidefocus>
			<input name="chk" type="checkbox" id=chk_openfor hidefocus>
			<span class="help" id="explorer_help"></span></a>
			<label for=chk_openfor id="explorer_label"></label>
		</td>
	</tr>
	<tr>
		<td>
			<a class="help" href="#" hidefocus>
			<input name="chk" type="checkbox" id=chk_ses hidefocus>
			<span class="help" id="explorer_help"></span></a>
			<label for=chk_ses id="explorer_label"></label>
		</td>
	</tr>
</table>
</fieldset>

<fieldset style="margin-top:4pt"><legend id="ie_legend"></legend><table width=100%>
	<tr>
		<td>
			<a class="help" href="#" hidefocus>
			<input name="chk" type="checkbox" id=chk_html_def hidefocus>
			<span class="help" id="ie_help"></span></a>
			<label for=chk_html_def id="ie_label"></label>
		</td>
	</tr>
	<tr>
		<td>
			<a class="help" href="#" hidefocus>
			<input name="chk" type="checkbox" id=chk_html hidefocus>
			<span class="help" id="ie_help"></span></a>
			<label for=chk_html id="ie_label"></label>
		</td>
	</tr>
</table></fieldset>

<fieldset style="margin-top:4pt"><legend id="win_legend"></legend><table width=100%>
<tr>
	<td>
		<a class="help" href="#" hidefocus>
		<input name="chk" type="checkbox" id=chk_helper hidefocus>
		<span class="help" id="win_help"></span></a>
		<label for=chk_helper id="win_label"></label>
	</td>
</tr>
</table></fieldset>

<table style="width:100%; margin-top:4pt">
	<tr>
		<td align=center width=33%><input type="button" class="btn" onClick="if (!Set()){self.location.reload()}" id="btn_ok" value="OK"></td>
		<td align=center width=33%><input type="button" class="btn" onClick="self.close();" id="btn_cancel" value=""></td>
		<td align=center width=33%><input type="button" class="btn" onClick="About();" id="btn_about" value=""></td>
	</tr>
</table>
</td></tr>
</form>
</table>
</body>
</html>
